// pages/dynamic/dynamic.js
Page({
  data: {
    active: 0,
    typeList: [{
      key: 1,
      value: "心情动态"
    }, {
      key: 2,
      value: "自家售卖"
    }, {
      key: 3,
      value: "出租招租"
    }, {
      key: 5,
      value: "二手商品"
    }, {
      key: 6,
      value: "旅游代买"
    }, {
      key: 7,
      value: "技能墙"
    }],
    type: "",
    list: [],
    page: 1,
    size: 10,
    isNoMore: true,
    isLoding: true
  },
  onLoad: function (options) {
    this.getList();
  },
  getList() {
    let params = {
      page: this.data.page,
      size: this.data.size,
      type: this.data.type,
      createTime: this.data.page == 1 ? "" : this.data.list[this.data.list.length - 1].createTime,
      id: this.data.page == 1 ? "" : this.data.list[this.data.list.length - 1].id,
      pageType: 1
    }
    getApp().globalData.http.list(params).then(res => {
      let data_tmp = [...this.data.list, ...res.data];
      this.setData({
        list: data_tmp,
        isLoding: true
      });
      if (this.data.list.length == res.count) {
        this.setData({
          isNoMore: false
        });
      }
    });
  },
  onReachBottom() {
    if (this.data.isNoMore) {
      this.setData({
        page: this.data.page / 1 + 1,
        isLoding: false
      });
      this.getList();
    }
  },
  tab(e) {
    if (e.detail.index == 2) {
      wx.switchTab({
        url: "/pages/morejob/list/list",
      });
    } else {
      this.setData({
        active: e.detail.index,
        list: [],
        page: 1,
        isNoMore: true,
        isLoding: true
      });
      this.getList();
    }
  },
  typeSel(e) {
    this.setData({
      type: e.currentTarget.dataset.type,
      list: [],
      page: 1,
      isNoMore: true,
      isLoding: true
    });
    this.getList();
  },
  thumbup(e) {
    getApp().globalData.http.thumbup({
      id: e.currentTarget.dataset.id
    }).then(res => {
      this.setData({
        ["list[" + e.currentTarget.dataset.index + "].isThumbsUp"]: 1,
        ["list[" + e.currentTarget.dataset.index + "].thumbsUp"]: this.data.list[e.currentTarget.dataset.index].thumbsUp / 1 + 1,
      });
    });
  },
  thumbupList(e) {
    wx.navigateTo({
      url: "/pages/my/likedlist/likedlist?id=" + e.currentTarget.dataset.id,
    });
  },
  previewImg(e) {
    let arr = e.currentTarget.dataset.img;
    let current = e.currentTarget.dataset.current;
    getApp().globalData.util.previewImage(arr, current);
  }
})